package com.ctp.ui.table.renderer;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;

public class TableToolTipRenderer implements TableCellRenderer {

	private JLabel label = new JLabel();

	public TableToolTipRenderer() {
		label.setFont(UIManager.getFont("Table.font"));
		label.setHorizontalAlignment(JLabel.CENTER);
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		if (value == null) {
			label.setText("");
		} else {
			String[] newValues = value.toString().split(";", 2);

			label.setText(newValues[0]);
			if (newValues.length > 1) {
				label.setToolTipText(newValues[1]);
			} else {
				label.setToolTipText(null);
			}
		}

		return label;
	}

}
